package com.xuya.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.xuya.dao.ProductDao;
import com.xuya.entity.Adminer;
import com.xuya.entity.Product;

public class HomeServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		Adminer adminer = (Adminer) session.getAttribute("user");
		if(adminer == null){
			resp.sendRedirect("index.jap?code=10003");
			return;//必须要结束程序，否则会出现双重的跳转
		}
		ProductDao pdao = new ProductDao();
		List<Product> list = pdao.findAllProduct();
		req.setAttribute("prodlist",list);
		req.getRequestDispatcher("main.jsp").forward(req, resp);
	}
}
